package codingforgreat.lchot150;

import java.util.ArrayList;
import java.util.List;

public class Lc017 {
    public char[][] phone = new char[][]{
            {'a','b','c'},
            {'d','e','f'},
            {'g','h','i'},
            {'j','k','l'},
            {'m','n','o'},
            {'p','q','r','s'},
            {'t','u','v'},
            {'w','x','y','z'}
    };
    public List<String> letterCombinations(String digits) {
        List<String> ans = new ArrayList<>();
        if(digits == null || digits.length() == 0){
            return ans;
        }

        char[] str = digits.toCharArray();
        char[] path = new char[str.length];
        process(str,0,path,ans);
        return ans;
    }
    public void process(char[] s,int index,char[] path,List<String> ans){
        if(index == s.length){
            ans.add(String.valueOf(path));
            return;
        }
        char[] cur = phone[s[index] - '2'];
        for(int i = 0;i < cur.length;i++){
            path[index] = cur[i];
            process(s,index + 1,path,ans);
        }
    }
}
